﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using 坦克大战.Properties;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace 坦克大战
{
    public partial class Form1 : Form
    {
        private Thread t;
        private static Graphics windowg;
        private static Bitmap tempBmp;
        public Form1()
        {
            InitializeComponent();
            this.StartPosition= FormStartPosition.CenterScreen;

            windowg = this.CreateGraphics();


            tempBmp = new Bitmap(450,450);
            Graphics bmpg = Graphics.FromImage(tempBmp);
            GameFrameWork.g = bmpg;

            t = new Thread(new ThreadStart(GameMianThread));
            t.Start();


        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {

            

        }
        private static void GameMianThread()
        {
            GameFrameWork.Start();

            int sleepTime = 1000 / 60;

            while(true)
            {
                GameFrameWork.g.Clear(Color.Black);
                GameFrameWork.Update();
                windowg.DrawImage(tempBmp, 0, 0);
                Thread.Sleep(sleepTime);
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            t.Abort();
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            GameObjectManager.KeyUp(e);
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            GameObjectManager.KeyDown(e);
        }
    }
}
